// pages/self/orderInformation/orderInformation.js
var app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    classfiySelect:"",
      doctorId:"",
      fieldid:"",
      rigId:'01',
      leftText: [{
        id: "01",
        office: "今日预约",
      },
      {
        id: "02",
        office: "近期预约",
      },
      {
        id: "03",
        office: "逾期预约",
      },],
      rightData: [{
        id: "01",
        title:"今日预约",
        frist: [/*{
          url: "/pages/images/8.png",
          doctorname: "张医生",
          doctortitle: "特邀专家",
          doctorid:"10",          
          clinicType:'01',
          times:"2020-12-1"
        },
        {
          url: "/pages/images/8.png",
          doctorname: "张医生",
          doctortitle: "特邀专家",
          doctorid:"20",
          clinicType:'01',
          times:"2020-12-1"
        },
        {
          url: "/pages/images/8.png",
          doctorname: "张医生",
          doctortitle: "特邀专家",
          doctorid:"10",
          clinicType:'01',
          times:"2020-12-1"
        },
        {
          url: "/pages/images/8.png",
          doctorname: "张医生",
          doctortitle: "特邀专家",
          doctorid:"20",
          clinicType:'01',
          times:"2020-12-1"
        },
        {
          url: "/pages/images/8.png",
          doctorname: "张医生",
          doctortitle: "特邀专家",
          doctorid:"10",
          clinicType:'01',
          times:"2020-12-1"
        },
        {
          url: "/pages/images/8.png",
          doctorname: "张医生",
          doctortitle: "特邀专家",
          doctorid:"20",
          clinicType:'01',
          times:"2020-12-1"
        }*/
      ],
      },
      {
        id: "02",
        title:"近期预约",
        frist: [
          /*{
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"10",
            clinicType:'02',
            times:"2020-12-1"
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"20",
            clinicType:'02',
            times:"2020-12-1"
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"10",
            clinicType:'02',
            times:"2020-12-1"
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"20",
            clinicType:'02',
            times:"2020-12-1"
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"10",
            clinicType:'02',
            times:"2020-12-1"
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"20",
            clinicType:'02',
            times:"2020-12-1"
          }*/
        ],
      },
      {
        id: "03",
        title:"逾期预约",
        frist: [
          /*{
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"10",
            clinicType:'03',
            times:"2020-12-1"
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"20",
            clinicType:'03',
            times:"2020-12-1"
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"10",
            clinicType:'03',
            times:"2020-12-1"
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"20",
            clinicType:'03',
            times:"2020-12-1"
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"10",
            clinicType:'03',
            times:"2020-12-1"
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"20",
            clinicType:'03',
            times:"2020-12-1"
          }*/
        ],
      },
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      classfiySelect: this.data.leftText[0].id,
    })
    console.log(getApp().globalData.doctorId)
    var that = this;
    wx.request({
      url:  getApp().globalData.url+'patientorderrecord', // 仅为示例，并非真实的接口地址
      method: 'GET',
      data: {
        unitphone:getApp().globalData.unitphone
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success(res) {  
        console.log(res.data)
        let fi={};
        let first1=[];
        let first2=[];
        let first3=[];
          for(let i=0;i<res.data.length;i++)
          {
            var date0 = res.data[i].orderForm.bootDate;
            var today = new Date();
            today = today.toISOString().slice(0,10)
            var doctorId0="";
            var doctorRank0="";
            var doctorName0 ="";
            var photoUrl0="";
            var bookId0 ="";
            var times0="";
            doctorName0=res.data[i].doctorName;
            doctorId0=res.data[i].orderForm.doctorId;
            doctorRank0=res.data[i].doctorRank;
            photoUrl0=res.data[i].doctorPhoto;
            bookId0=res.data[i].orderForm.bootId;
            times0=res.data[i].orderForm.bootDate + " "+res.data[i].orderForm.bootTime;
            console.log(i)
            console.log(date0)
            console.log(today)
            if(date0==today&&res.data[i].orderForm.progress=="未就诊")
            {
              console.log("一")
              fi ={"doctorname":doctorName0,"doctortitle":doctorRank0,"doctorid":doctorId0,"url":photoUrl0,"clinicType":that.data.leftText[0].id,"bookid":bookId0,"times":times0};        
              first1.push(fi);
            }
            else if(date0>today)
            {
              console.log("二")
              fi ={"doctorname":doctorName0,"doctortitle":doctorRank0,"doctorid":doctorId0,"url":photoUrl0,"clinicType":that.data.leftText[1].id,"bookid":bookId0,"times":times0};        
              first2.push(fi);
            }
            else if(date0<today&&res.data[i].orderForm.progress=="未就诊")
            {
              console.log("三")
              fi ={"doctorname":doctorName0,"doctortitle":doctorRank0,"doctorid":doctorId0,"url":photoUrl0,"clinicType":that.data.leftText[2].id,"bookid":bookId0,"times":times0};        
              first3.push(fi);
            }
          }

            that.setData({
              "rightData[0].frist":first1
            })

            that.setData({
              "rightData[1].frist":first2
            })


            that.setData({
              "rightData[2].frist":first3
            })
 
      },
      fail(res){
        wx.showToast({
          title: '网络连接失败，请重新尝试',
          icon:'none'
        })
      }
    })
  },
  toTalkWith:function(e){
    console.log(e);
    var chooseId=e.currentTarget.dataset.id;
    console.log(chooseId);
    var doctorName =e.currentTarget.dataset.name
    var doctorImg = e.currentTarget.dataset.img
    console.log(doctorName);
    console.log(doctorImg);
    wx.navigateTo({
      url:'../../onlineConsultation/onlineConsultation?doctorId='+chooseId + '&&doctorName=' + doctorName + '&&doctorImg=' + doctorImg,
      //
      //url:'../../../pages/onlineConsultation/onlineConsultation?doctorId='+chooseId,
   });


  },
  scroll: function(e) {
    var scrollTop = e.detail.scrollTop,
    h = 0,
    classfiySelect;
    var that = this;
    that.data.leftText.forEach(function(clssfiy, i) {
      var _h =26 + that.length(clssfiy['id'])*102;
      if (scrollTop >= h){
        classfiySelect = clssfiy['id'];
      }
    h +=_h;
    })
    that.setData({
    classfiySelect: classfiySelect,
    })
    console.log(that.data.classfiySelect)
  },
  //求每一栏高度
  length: function(e) {
    var that = this;
    var rightData = that.data.rightData;
    for (var i = 0; i < rightData.length; i++) {
      if(rightData[i]['id']==e){
        return rightData[i]['frist'].length;
      }
    }
  },
  //点击左边事件
  left_list: function(e) {
    var that = this;
    var l_id = e.currentTarget.dataset.id;
    that.setData({
      rigId: l_id,
    })
  },
  
  toRecords: function(e){
    var chooseBook = e.target.dataset.index;
    console.log(chooseBook)
    app.globalData.bookId=chooseBook
    console.log(app.globalData.bookId)
    wx.showModal({
      title: '提示',
      content: '您确定要取消预约吗?',
      success: function (res) {
        if (res.confirm) {//这里是点击了确定以后
          var that = this;
          wx.request({
            url:  getApp().globalData.url+'patientcancelorder', // 仅为示例，并非真实的接口地址
            method: 'GET',
            data: {
                bookId:getApp().globalData.bookId
            },
            header: {
              'content-type': 'application/x-www-form-urlencoded' // 默认值
            },
            success(res) {
              console.log(res.data)
              if(res.data.success=="True")
              {
                wx.navigateTo({
                  url: '../cancelOperation/cancelOperation',
                })
              }
              else
              {
                wx.showToast({
                title: '取消失败',
                icon: 'none',
                })
              }
            },
            fail(res){
            
            }
          })
       }
        else {//这里是点击了取消以后
        }
 
      }
 
    })
    
  },
  toAppointment: function(e){
    var chooseBook = e.target.dataset.index;
    console.log(chooseBook)
    app.globalData.bookId=chooseBook
    console.log(app.globalData.bookId)
    wx.navigateTo({
      url: '../appointInformation/appointInformation',
    })
 
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})